
	<div class="ibox float-e-margins">
		<div class="ibox-title" style="border: none;">
			<h5 style="color: #00afef"><i>GL Accounts</i></h5>
				<div class="ibox-tools add">
					<button id="save_gl_account" class="btn btn-primary btn-sm save-btn-tab" type="">Save</button>
					<button id="cancel_add" class="btn-outline btn btn-primary btn-sm add-cancel cancel-btn-tab" >Cancel</button>
				</div>
		</div>
		<div class="ibox-content">
			<form class="form-horizontal" id="glAddForm">
				<div class="form-group"> <label class="col-lg-4 control-label">Company</label>
					<div class="col-lg-4">
						<input readonly type="text" value="<?php echo $this->session->userdata('comp_name'); ?>" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-lg-4 control-label">Code</label>
					<div class="col-lg-5">
						<input type="text" name="gl_code" id="gl_code" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-lg-4 control-label">Name</label>
					<div class="col-lg-5">
						<input type="text" name="gl_name" id="gl_name"  class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">Sales Account</label>
					<div class="col-sm-4">
						<select id="gl_type_select" class="form-control m-b" name="gl_type">
							<option value="">Select</option>
							<?php foreach ($glLookups as $lookup_type) {if ($lookup_type->lookup_type == "GL_ACCOUNT_TYPE") {?>
							 <option value="<?php echo $lookup_type->lookup_code; ?>"><?php echo $lookup_type->meaning; ?></option>
							 <?php }}
?>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">Sub-Type</label>
					<div class="col-sm-4">
						<select class="form-control m-b" id="gl_sub-type" name="gl_sub_type">
							<option value="">Select</option>
							<?php foreach ($glLookups as $lookup_type) {if ($lookup_type->lookup_type == "GL_ACCOUNT_SUB_TYPE") {?>
							<option value="<?php echo $lookup_type->lookup_code; ?>"><?php echo $lookup_type->meaning; ?></option> <?php }}
?>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-lg-4 control-label">Enable</label>
					<div class="col-lg-1">
						<input type="checkbox" value="ok" name="gl_enabled" class="i-checks" checked>
					</div>
				</div>
			</form>
		</div>
	</div>

	<script type="text/javascript">
	$(document).ready(function() {
		$('#glAddForm').data('serialize',$('#glAddForm').serialize());
		$('select').chosen({width: '100%'});
		$('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        $(document).on('click','#save_gl_account',function(){
            if($("#glAddForm" ).valid() == true){
                $.ajax({
	                url:"<?php echo base_url($this->session->userdata('forajax') . '/add_Account'); ?>",
	                method:'post',
	                data:$('#glAddForm').serialize(),
	                dataType:'json',
	                success: function (data) {
	                    if(data.err == 1){
	                    	notifymsg('danger',data.msg);
	                    }else{
	                    	$('#add-link').remove();
		                    $('#add').remove();
		                    $('#tab-list-2 a:first').tab('show');
		                    $('#count_add').val('0');
		                    notifymsg('success','<b>Success</b>: Data Saved.');
	                    }

	                },
	                beforeSend: function(){

	                }
	            });
            }
        });

        function alert_cancel(){
                if($('#glAddForm').serialize()!=$('#glAddForm').data('serialize')){
                // Form has changed!!!
                swal({
                  title: "Are you sure?",
                  text: "Your work will not be save",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "Leave",
                  cancelButtonText: "Stay",
                  closeOnConfirm: true,
                  closeOnCancel: true },
              function (isConfirm) {
                  if (isConfirm) {
                    swal("success");
                      close_add(); active_search();
                      notifyClass("clear","");
                  } else {
                      swal("Cancelled");
                  }
              });
                }else{
                    close_add(); active_search();
                    notifymsg("hide","hide");
                }
            }
        $('#cancel_add').click(function(){
            alert_cancel();
        });

        $('#addX').click(function(){
            alert_cancel();
        });

        $("#glAddForm").validate({
                 rules: {
                     gl_name: {
                        required: true
                     },
                     gl_sub_type: {
                     	required : true
                     },
                     gl_type: {
                        required: true
                     }
                 }
        });
	});
	</script>